<template>
	<view class="applyWithdrawal"  :style="{ '--bg-image': `url(${moban})` }">
		<view class="imageBackground flex-column">
			<view class="text-align_center commission" v-if="userInfo&&userInfo.surplus_income">
				<view style="color: rgb(255, 255, 255);">
					 {{'我的收益('+currency_name+')'}}
				</view>
				<view style="color: rgb(255, 255, 255);font-size: 60rpx;">
					{{userInfo.surplus_income}}
				</view>
			</view>
			<view class="dataDetail">
				<view class="">
					我的收益
				</view>
				<view class="flex-between " style="margin: 30rpx 0;">
					<view>
						<!-- <text class="font32">￥</text> -->
						<text style="font-size: 56rpx;">{{userInfo.surplus_income}}</text>

					</view>
					<!-- <view class="withdrawalBtn flex" @click="allWithdrawals()">
						全部提现
					</view> -->
				
				</view>
				<view class="flex-between padding-top_20rpx">
					<view class="flex-column" v-for="(item,i) in monthDataDetails" :key="i">
				
						<view class="margin-bottom_10rpx" style="color:rgb(102, 102, 102);font-size: 28rpx;">
							<text>{{item.text}}</text>
						</view>
						<view class="font-weight_bold" style="color: rgb(51, 51, 51);font-size: 28rpx;">
							{{totelName(item.number)}}
						</view>
				
					</view>
				
				</view>
				
				<!-- <view class="flex-between">
					<view style="color: rgb(153, 153, 153);" >
						<text style="margin-bottom:10rpx">当前兑换比例1/{{basicConfiguration.recharge_ratio}}</text>
					</view>
					<view style="color: rgb(153, 153, 153);" v-if="basicConfiguration">
						<text
							style="color: red;">手续费{{basicConfiguration.withdrawal_fees_ratio}}%</text><text>，实际到账{{(allCommission-((Math.ceil(Number(basicConfiguration.withdrawal_fees_ratio))?Math.ceil(Number(basicConfiguration.withdrawal_fees_ratio)):0)* allCommission )/100).toFixed(2)}}</text>
					</view>
				</view> -->

			</view>
			<view class="dataDetail">
				<view class="">
					转出收益 <text>(收益转为余额)</text>
				</view>
				<view class="flex-between " style="margin: 30rpx 0;">
					<view>
						<!-- <text class="font32">￥</text> -->
						<!-- <text style="font-size: 56rpx;">{{userInfo.surplus_income}}</text> -->
						<input v-model="form.number"   type="number" />
			           
					</view>
					<view class="withdrawalBtn flex" @click="allWithdrawals()">
						全部
					</view>
				
				</view>
				
				
			
			
			</view>
			
			<view class="withdrawalNowBtn flex" @click="withdrawalNowFn()">
				转出收益(到余额)
			</view>
		</view>
	</view>

	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				zfb: this.$img.zfb,
				current: 0,
				tabIndex: 4,
				accountInfo: {
					accountName: '',
					accountNumber: '',

				},
				
				// 数据明细
				monthDataDetails: [{
						number: 0.00,
						text: '今年收益(' + uni.getStorageSync("system").currency_name + ')'
					},
					{
						number: 0.00,
						text: '本月收益(' + uni.getStorageSync("system").currency_name + ')'
					},
					{
						number: 0.00,
						text: '今日收益(' + uni.getStorageSync("system").currency_name + ')'
					},
				
				],
				currency_name:uni.getStorageSync("system").currency_name,
				userInfos: uni.getStorageSync("userInfo"),
				// 用户配置
				userInfo: null,
				// 基本配置
				basicConfiguration: {},
				token: uni.getStorageSync('login').token,
				// 全部佣金
				allCommission: 0,
				// 最多提现额度

				withdrawal_condition: '',
				// 最低提现额度
				everyday_withdrawal_amount: '',
				//" 1 支付宝 2 微信  3 支付宝和微信"
				withdrawal_mode: '',
				deduction_integral_ratio: 0,
				moban:this.$img.moban,
				// wx zfb
				payList: [{
					value: '1',
					name: '提现到微信',
					checked: 'true',
					disabled: false,
					image: this.$img.wxicom
				}, {
					value: '2',
					name: '提现到支付宝',
					image: this.$img.zfb,
					disabled: false,
					checked: 'false',
				}, ],
				form: {
					number: 0,
				
				}
			}
		},
		onLoad() {
			// 获取用户信息
			this.userInformation()
			// 获取基本配置
			this.basicConfigurationFn()
			
		},
		onShow() {
			this.$at.releaseKey('submit');
		},
		computed: {
		
			totelName: function() {
				return function(num) {
		
					if (num >= 10000) {
						let remainder = num % 10000;
						let quotient = Math.floor(num / 10000);
						let decimal = Math.floor(remainder / 1000);
						return quotient + '.' + decimal + '万';
					} else {
						return num.toString();
					}
				};
			}
		},
		methods: {
			radioChange(e) {
				console.log(e.detail.value)
				if (e.detail.value == 1) {
					this.form.name = ''
					this.form.account = ''
				}
				this.current = Number(e.detail.value) - 1
				this.form.pay_mode = Number(e.detail.value)
				
			},
			
			// 申请提现
			withdrawalNowFn() {
				this.$at.uniDoFunc({
					key: 'submit',
					success: async () => {
						this.$at.lockKey('submit');
						// console.log(this.form.number, Math.floor(182.56 * 100) / 100 )
						if(Math.floor(this.form.number * 100) / 100>Math.floor(this.userInfo.surplus_income * 100) / 100){
							this.$sun.toast('当前填写的收益大于可转出收益','none')
							this.$at.releaseKey('submit');
						}else{
							
							this.$at.releaseKey('submit');
							this.$sun.toast('掉接口','none')
							const result = await this.$http.post({
								url: this.$api.surplusToBalance,
								data: {
							
							     id: uni.getStorageSync("userInfo").id,
								 income:this.form.number
							
							
								},
								headers: {
									'Authorization': this.userInfos.token
								}
							
							})
							
							if (result.code == 0) {
								this.$at.releaseKey('submit');
								console.log('data', result.data);
								
								setTimeout(()=>{
									this.$sun.navBack()
								},500)
							  
							
							} else {
								this.$at.releaseKey('submit');
								this.$sun.toast(result.message, 'none')
							}
						}
                        

					}
				});
			},
			allWithdrawals() {
				this.deduction_integral_ratio = Math.floor((this.userInfo.surplus_income / this.basicConfiguration
						.recharge_ratio) *
					100) / 100;
				this.allCommission = this.deduction_integral_ratio
				this.form.number = this.userInfo.surplus_income
			},
			
			// 获取用户信息
			async userInformation() {
				const result = await this.$http.post({
					url: this.$api.userInfo,
					data: {




					},
					headers: {
						'Authorization': this.userInfos.token
					}

				})

				if (result.code == 0) {
					console.log('data', result.data);
					this.userInfo = result.data


				} else {
					this.$sun.toast(result.message, 'none')
				}
			},
			// 获取基本配置
			async basicConfigurationFn() {
				const res = await this.$http.post({
					url: this.$api.income,
					data: {
				
				
					},
					headers: {
						'Authorization': this.userInfos.token
					}
				
				})
				console.log(res)
				if (res.code == 0) {
					// 跳转到登录页面
					
					this.monthDataDetails.forEach((item) => {
						switch (item.text) {
							case '今年收益(' + uni.getStorageSync("system").currency_name + ')':
								item.number = res.data.year_amount;
								break;
							case '本月收益(' + uni.getStorageSync("system").currency_name + ')':
								item.number = res.data.month_amount;
								break;
							case '今日收益(' + uni.getStorageSync("system").currency_name + ')':
								item.number = res.data.today_amount;
								break;
				
						}
					})
				
					console.log(res.data)
					// this.$sun.toast(res.message, 'none')
				} else {
				
					this.$sun.toast(res.message, 'none')
				}
				
				const result = await this.$http.post({
					url: this.$api.config,
					data: {


					},
					headers: {
						'Authorization': this.userInfos.token
					}

				})
				if (result.code == 0) {
					console.log(result)
					this.basicConfiguration = result.data

					// payList: [{
					// 	value: '1',
					// 	name: '提现到微信',
					// 	checked: 'true',
					// 	disabled: false,
					// 	image: this.$img.wxicom
					// }, {
					// 	value: '2',
					// 	name: '提现到支付宝',
					// 	image: this.$img.zfb,
					// 	disabled: false,
					// 	checked: 'false',
					// },],
					// 判断当前 是否可以使用那个进行申请
					if (result.data.withdrawal_mode == '2') {
						// this.payList[1].disabled = true
						this.current = 0
						this.form.pay_mode = 1
						this.payList = [{
							value: '1',
							name: '提现到微信',
							checked: 'true',
							disabled: false,
							image: this.$img.wxicom
						}]

					} else if (result.data.withdrawal_mode == '1') {
						// this.payList[0].disabled = true
						this.current = 0
						this.form.pay_mode = 2
						this.payList = [{
							value: '2',
							name: '提现到支付宝',
							image: this.$img.zfb,
							disabled: false,
							checked: 'true',
						}]
						// this.payList[0].checked = true
					}
				}
			}

		}
	}
</script>

<style lang="less" scoped>
	page {
		background: #f6f6f6;
	}

	.imageBackground {

		background-repeat: no-repeat;
		background-size: contain;
		background-image: (var(--bg-image));

		.commission {
			margin-top: 190rpx;
		}

		.dataDetail {
			margin-top: 26rpx;
			width: 700rpx;
			// height: 264rpx;
			padding: 30rpx;
			border-radius: 20rpx;

			box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(0, 0, 0, 0.04);
			background: rgb(255, 255, 255);

			.withdrawalBtn {
				width: 120rpx;
				height: 44rpx;
				border-radius: 42rpx;
				font-size: 24rpx;
				background: #4a87fa;
				color: rgb(255, 255, 255);
			}
		}

		.withdrawalType {
			margin-top: 40rpx;
			border-radius: 20rpx;
			width: 700rpx;
			height: 114rpx;
			box-shadow: 0rpx 8rpx 8rpx 0rpx rgba(0, 0, 0, 0.02);
			background: rgb(255, 255, 255);
			padding: 28rpx 20rpx;

			.imgWxx {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.withdrawalNowBtn {
			margin-top: 96rpx;
			width: 566rpx;
			height: 96rpx;
			border-radius: 64rpx;

			box-shadow: inset 0px 4px 4px 0px rgba(255, 158, 148, 0.32), 0px 4px 4px 0px rgba(254, 82, 65, 0.15);
			background: #4a87fa;
			font-size: 32rpx;
			color: rgb(255, 255, 255);
		}

		.zfbCard {
			margin-top: 40rpx;
			width: 700rpx;
			height: 298rpx;
			border-radius: 20rpx;

			box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.04);
			background: rgb(255, 255, 255);
			padding: 16rpx;

			.border {
				border: 1rpx solid rgb(248, 248, 248);
				width: 651rpx;
				height: 0;
			}
		}
	}
</style>